package org.destiny.singletable.repository;

import java.util.List;

import org.destiny.singletable.entity.StudentPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * DAO层，用jpa习惯叫Repository层
 * 
 * @author destinys
 *
 */
@Repository
public interface StudentRepository extends JpaRepository<StudentPO, Long>, JpaSpecificationExecutor<StudentPO> {

    List<StudentPO> queryByUserName(String userName);

    @Query(value = "FROM StudentPO a WHERE a.school = :school")
    List<StudentPO> lookForBySchool(@Param("school") String school);

    @Query(value = "FROM StudentPO a WHERE a.school = ?1")
    List<StudentPO> seekBySchool(String school);

    /**
     * 修改操作
     * 
     * @param userNameAfter
     * @param id
     */
    @Modifying
    @Query("UPDATE StudentPO a SET a.userName = ?1 WHERE a.id = ?2")
    void updateById(String userName, Long id);
}
